import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '',
          name: 'home',
          component: () => import('@/views/home/index.vue')
        },
        {
          path: 'category/:id',
          name: 'category',
          component: () => import('@/views/category/index.vue')
        },
        {
          path: 'category/sub/:id',
          name: 'categorySub',
          component: () => import('@/views/categorySub/index.vue')
        },
        {
          path: 'detail/:id',
          name: 'detail',
          component: () => import('@/views/detail/index.vue')
        },
        {
          path: 'cartList',
          name: 'cartList',
          component: () => import('@/views/cartList/index.vue')
        },
        {
          path: 'checkout',
          name: 'checkout',
          component: () => import('@/views/checkout/index.vue')
        },
        {
          path: 'pay',
          name: 'pay',
          component: () => import('@/views/pay/index.vue')
        },
        {
          path: 'paycallback', // 注意路径，必须是paycallback
          component: () => import('@/views/pay/payBack.vue')
        },
        {
          path: 'member',
          redirect: 'member/user',
          component: () => import('@/views/member/index.vue'),
          children: [
            {
              path: 'user',
              component: () => import('@/views/member/components/MemberInfo.vue')
            },
            {
              path: 'order',
              component: () => import('@/views/member/components/MemberOrder.vue')
            }
          ]
        },
      ]
    },
    {
      path: '/login',
      component: () => import('@/views/login/index.vue')
    }
  ],
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
